package TeamView;

import TeamService.NameListService;
import TeamService.TeamService;
import Teamdomain.Employee;
import Teamdomain.Progammer;

import java.util.zip.DeflaterOutputStream;

/**
 * @program: Demo2
 * @description:
 * @author: Yan Guang
 * @create: 2020-04-22 17:44
 */
public class TeamView {
    private NameListService nameListService = new NameListService();
    private TeamService teamService = new TeamService();

    public void enterMainMenu() {
        boolean isfagle = true;
        while (isfagle) {
            listAllEmployees();
            char menu = TSUtility.readMenuSelection();
            switch (menu) {
                case '1':
                    getTeam();
                    break;
                case '2':
                    addMember();
                    break;
                case '3':
                    deleteMember();
                    break;
                case '4':
                    System.out.println("是否确定删除，请选择Y/N");
                    char exit = TSUtility.readConfirmSelection();
                    if (exit == 'Y') {
                        isfagle = false;
                    }
            }
        }
    }

    private void listAllEmployees() {
        System.out.println("--------------所有人员--------------");
        Employee[] employees=nameListService.getAllEmployees();
        if (employees ==null||employees.length==0){
            System.out.println("此时没有人员");
        }else {
            System.out.println("___________所有属性___________________");
            for (int i = 0; i < employees.length; i++) {
                System.out.println(employees[i].toString());
            }
        }
        System.out.println("--------------结束--------------");

    }

    private void getTeam() {
        System.out.println("--------------小组人员--------------");
        Progammer[] Progammers=teamService.getTeam();
        if (Progammers ==null||Progammers.length==0){
            System.out.println("小组没有人员");
        }else {
            System.out.println("___________所有属性___________________");
            for (int i = 0; i < Progammers.length; i++) {
                System.out.println(Progammers[i].toString());
            }
        }
        System.out.println("--------------结束--------------");
    }

    private void addMember() {
        System.out.println("--------------添加人员--------------");
        System.out.println("请输入要添加的员工");
        int name= TSUtility.readInt();

//        try{
//            Employee employee=nameListService.getEmployee(name);
//            teamService.addMember(employee);
//            System.out.println("添加成功");
//        } catch (TeamException e) {
//            System.out.println("错误"+(e));
//        }
        TSUtility.readReturn();
        System.out.println("--------------结束--------------");
    }

    private void deleteMember() {
        System.out.println("--------------删除人员--------------");
        int id=TSUtility.readInt();
        System.out.println("确认是否删除Y/N");
        char makesure=TSUtility.readConfirmSelection();
        if (makesure=='N'){
            return ;
        }else {
//            try {
//                Employee employee=nameListService.getEmployee(id);
//                teamService.removeMember(id);
//                System.out.println("删除成功");
//            } catch (TeamException e) {
//                System.out.println("删除失败"+"getMaeages");
//            }
        }
        System.out.println("--------------结束--------------");
    }

    public static void main(String[] args) {
        TeamView teamView = new TeamView();
        teamView.enterMainMenu();
    }
}
